/**
 * @author maulin
 */
dojo.provide("medryx.widgets._Providers.ProvidersView");
dojo.require("medryx.widgets.Headshot");

dojo.declare("medryx.widgets._Providers.ProvidersView", null, {
	templateString: '<table dojoAttachPoint="containerNode" class="providers"><tbody dojoAttachPoint="body"></tbody></table>',
	filter: null,
	sort: [{field:"lastName"}, {field:"firstName"}],
	columns: 4,
	clickable: false,
	$loadProviders:null,
	postCreate: function() {
		var deferred = this.loadProviders(this.filter, this.sort);
        deferred.addCallback(dojo.hitch(this, function(results) {
			this.buildView(results, this.body, this.columns, this.clickable);
		}));
		
	},
	
	buildView:function(providers, table, numberOfColumns, clickable) {
		var tr;
        var currentCol = 0;
       dojo.forEach(providers, function(provider, index) {
			if (currentCol++ % numberOfColumns === 0) {
				tr = dojo.doc.createElement("tr");
				table.appendChild(tr);
			}
			var td = dojo.doc.createElement("td");
			tr.appendChild(td);
			var div = dojo.doc.createElement("div");
			td.appendChild(div);
			var headshot = new medryx.widgets.Headshot({
				provider: provider,
				clickable: clickable
			}, div);
			dojo.connect(headshot, "onProviderClicked", this, "onProviderClicked");
		}, this);
	},
	
	onProviderClicked: function(provider, e) {
		
	}
});
